/*
 * Copyright (c) 2017, Iotelligent Corporation
 * All rights reserved.
 *
 * Description:
 *
 *   RDB4 board level definitions.
 */

#ifndef __BOARD_H__
#define __BOARD_H__

//#include "ibat2000_conf.h"
//#include "hardware_mcu.h"
#include "stm32f4xx.h"

/* Global definitions */
#define BOARD_NAME                      "iBAT2000 RDB4"
#define BOARD_ID                        0x09
#define DEFAULT_DEVICE_SERIALS_NUMBER   0xABCD1234
#define DEFAULT_DEVICE_COMM_ADDRESS     (DEFAULT_DEVICE_SERIALS_NUMBER & 0xFFFF)


/*
 * Peripherals definitions
 */

/* Host communication UART */
#define UART_HOST                       USART1
#define UART_HOST_IRQn                  USART1_IRQn
//#define UART_HOST                       UART0
//#define UART_HOST_IRQn                  UART0_IRQn
//#define UART_HOST_BAUD_RATE             921600
//#define UART_HOST_BAUD_RATE             460800
#define UART_HOST_BAUD_RATE             230400

/* Debug shell UART */
#define UART_CLI                        USART2
#define UART_CLI_IRQn                   USART2_IRQn
//#define UART_CLI                        UART1
//#define UART_CLI_IRQn                   UART1_IRQn
#define UART_CLI_BAUD_RATE              115200

/* SPI Flash */
#define SPI_FLASH                       SPI0
#define SPI_FLASH_IRQn                  SPI0_IRQn

/* GPIO used to control boot mode */
#define GPIO_BOOT_MODE                  GPIO_2

/* SPI Bus */
#define SPI_BUS                         SPI1
#define SPI_BUS_IRQn                    SPI1_IRQn

/* SPI SM Slave*/
#define SPI_SM_Slave                    SPI1
#define SPI_SM_Slave_IRQn               SPI1_IRQn

/* SPI SM Master*/
#define SPI_SM_Master                   SPI2
#define SPI_SM_Master_IRQn              SPI2_IRQn



/* Software timer */
#define TIMER_SW                        TIM0
#define TIMER_COUNTER                   TIM1

/* GPIOs used to control RF switch */
//#define GPIO_ANT_V1                     GPIO_1
//#define GPIO_ANT_V2                     GPIO_1

/* GPIOs used to control PMIC */
#define GPIO_IBAT2000_CLK               GPIO_26
#define GPIO_IBAT2000_MISO              GPIO_25
#define GPIO_IBAT2000_MOSI              GPIO_24

/* GPIO for RF Enable */

#if IBat200_V1
#define GPIO_RF_EN                      GPIO_19

#elif IBat200_V2
#define GPIO_RF_EN                      GPIO_24
#endif
/* GPIO for buzzer */
//#define GPIO_BUZZER                     GPIO_12

/*
 * Board-level definitions
 */

/* Maximum tx power of the board */
#define RF_MAX_TX_OUTPUT_PWR_DBM        31

/* The antenna detect threshold */
//#define DEFAULT_RF_ANTENNA_RL_THR       14
#define DEFAULT_RF_ANTENNA_RL_THR       2

/* Rx path insertion loss */
#define RX_PATH_INSERTION_LOSS          11

/* Maximum number of rf tx port */
#define RF_MAX_TX_PORTDEF               1
#define DEFAULT_RF_ANTENNA_PORT         0

/* SJC configuration */
#define IN_SJC_DEF                      0
#define EXT_SJC_DEF                     1
#define SJC_COM_DEF                     IN_SJC_DEF

/* AuxADC configurations */
#define AUXADC_TEMP_SENSE_CH            AUXADC_EXTERNAL_0
#define AUXADC_RF_FWR_CH                AUXADC_EXTERNAL_2
#define AUXADC_RF_RXIN_CH               AUXADC_EXTERNAL_1

/* Power supply source (PMIC or Power backup) */
#define POWER_PMIC                      0
#define POWER_BKP                       1
#define POWER_SUPPLY_SRC                POWER_BKP


void sys_gpio_init( void );

void vco_ldo_enable( void );
void vco_ldo_disable( void );

void buzzer_on( void );

void rf_pa_enable( void );
void rf_pa_disable( void );

void auxadc_temp_sense( float *temp );
void auxadc_rf_fwd_power( float *tx_output );
void auxadc_rf_rxin_power( float *rx_input );

void sjc_init( void );
void sjc_start( void );

#endif /* __BOARD_H__ */

